<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%
	//查询前十名的诊断你
	String yydm =  input.getDesc("yydm","02");//医院代码
	String ksdm = input.getDesc("ksdm","-1"); //传入科室代码代表该科室主任
	String date = input.getDesc("start_date","2017-11-10");//开始时间
	String endDa = input.getDesc("end_date","2018-12-27");//结束时间

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
	String nowDate = sdf2.format(sdf.parse(date));
	String nowEndDa = sdf2.format(sdf.parse(endDa));
	
	String startDate = nowDate+"00:00:00";
	String endDate = nowEndDa+"23:59:59";

	String sqlWhere = " and mj.ghrq > '"+ startDate + "' and mj.ghrq < '" + endDate+"' " ;
	if(!yydm.equals("-1"))
	sqlWhere += " and mj.ksdm in (select new map (id as id) from his_dept where yydm ='"+yydm+"') " ;
	if(!"-1".equals(ksdm)){
		sqlWhere += " and mj.ksdm in(" + ksdm+")";
	
	}
	//前十名诊断
	
	String hql = "select  new map(mz.zdmc as zdmc , count( mz.zdmc) as count) from mzzd mz , mzjl mj where mj.xh = mz.ghxh " + sqlWhere + " group by mz.zdmc order by count(mz.zdmc) desc";
	List<Map> zdList =QBuilder.db("basedb").queryHql(hql,10);
	for(Map map : zdList){
		map.put("count",map.get("count")+"");
	}
	Message msg = new Message();
	msg.put("errcode",0);
	msg.put("diagnosed",zdList);
	msg.put("count",zdList.size());
	out.println(msg);
%>